home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
lib
/
c
/
string
/
RCS
/
strncmp.c,v
< prev
next >
Wrap
Text File
|
1992-03-27
|
3KB
|
134 lines
head 1.3;
branch ;
access ;
symbols ;
locks ; strict;
comment @ * @;
1.3
date 92.03.27.13.30.04; author rab; state Exp;
branches ;
next 1.2;
1.2
date 89.03.22.16.07.11; author rab; state Exp;
branches ;
next 1.1;
1.1
date 88.04.25.13.25.49; author ouster; state Exp;
branches ;
next ;
desc
@@
1.3
log
@A few little optimizations.
@
text
@/*
* strncmp.c --
*
* Source code for the "strncmp" library routine.
*
* Copyright 1988 Regents of the University of California
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#ifndef lint
static char rcsid[] = "$Header: /sprite/src/lib/c/string/RCS/strncmp.c,v 1.2 89/03/22 16:07:11 rab Exp Locker: rab $ SPRITE (Berkeley)";
#endif /* not lint */
#include <string.h>
/*
*----------------------------------------------------------------------
*
* strncmp --
*
* Compares two strings lexicographically.
*
* Results:
* The return value is 0 if the strings are identical in their
* first s1 characters. If they differ in their first s1
* characters, then the return value is 1 if the first string is
* greater than the second, and -1 if the second string is less
* than the first. If one string is a prefix of the other then
* it is considered to be less (the terminating zero byte participates
* in the comparison).
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
strncmp(s1, s2, numChars)
register char *s1, *s2; /* Strings to compare. */
register int numChars; /* Max number of chars to compare. */
{
register char c1, c2;
for ( ; numChars > 0; --numChars) {
c1 = *s1++;
c2 = *s2++;
if (c1 != c2) {
return c1 - c2;
}
if (c1 == '\0') {
return 0;
}
}
return 0;
}
@
1.2
log
@*** empty log message ***
@
text
@d17 1
a17 1
static char rcsid[] = "$Header: /sprite/src/lib/c/string/RCS/strncmp.c,v 1.1 88/04/25 13:25:49 ouster Exp Locker: rab $ SPRITE (Berkeley)";
d49 7
a55 7
for ( ; numChars > 0; numChars -= 1) {
if (*s1 != *s2) {
if (*s1 > *s2) {
return 1;
} else {
return -1;
}
d57 1
a57 1
if (*s1++ == 0) {
a59 1
s2 += 1;
@
1.1
log
@Initial revision
@
text
@d17 4
a20 2
static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
#endif not lint
@